<template>
  <a-card :bordered="false">
    <div style="display: flex; justify-content: space-between">
      <!-- 操作按钮区域 -->
      <div class="table-operator">
        <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>

        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-menu slot="overlay">
            <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
          </a-menu>
          <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
        </a-dropdown>
      </div>
      <!-- 查询区域 -->
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
      >
        <!-- 状态 -->
        <template slot="isOpen" slot-scope="text, record">
          <a-switch default-checked :checked="record.isOpen == 1 ? true : false" @change="statusChange(record)" />
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <xhdjSlideshow-modal ref="modalForm" @ok="modalFormOk"></xhdjSlideshow-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import XhdjSlideshowModal from './modules/xhdjFrontAnnouncementModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getFileAccessHttpUrl, httpAction } from '@/api/manage'

export default {
  name: 'xhdjFrontAnnouncementList',
  mixins: [JeecgListMixin],
  components: {
    XhdjSlideshowModal
  },
  data () {
    return {
      description: '轮播图配置表管理页面',
      options: [
        {
          value: '1',
          label: '启用'
        },
        {
          value: '0',
          label: '禁用'
        }
      ],
      // 表头
      columns: [
        {
          title: '排序',
          align: 'center',
          dataIndex: 'sortIndex'
        },

        {
          title: '标题',
          align: 'center',
          dataIndex: 'title'
        },

        {
          title: '状态',
          align: 'center',
          dataIndex: 'isOpen',
          scopedSlots: { customRender: 'isOpen' }
        },

        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 120,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/basics/xhdjFrontAnnouncement/list',
        edit: '/basics/xhdjFrontAnnouncement/edit',
        delete: '/basics/xhdjFrontAnnouncement/delete',
        deleteBatch: '/xhdjSlideshow/deleteBatch',
        exportXlsUrl: 'xhdjSlideshow/xhdjSlideshow/exportXls',
        importExcelUrl: 'xhdjSlideshow/xhdjSlideshow/importExcel'
      }
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    getAvatarView: function (avatar) {
      return getFileAccessHttpUrl(avatar)
    },
    // 改变状态
    statusChange (record) {
      console.log(record, !record.isOpen)

      let a = {
        content: record.content,
        id: record.id,
        sortIndex: record.sortIndex,
        title: record.title,
        isOpen: record.isOpen ? 0 : 1
      }

      console.log(a)

      httpAction(this.url.edit, a, 'put').then(res => {
        if (res.success) {
          this.loadData()
          this.$message.success(res.message)
        } else {
          this.$message.warning(res.message)
        }
      })
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
.ant-row {
  display: flex;
  justify-content: flex-end;
}
.ant-col {
  display: flex;
  justify-content: flex-end;
}
</style>
